package backend.model.admin;

import backend.model.base.DBModel;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.*;

@NamedQueries({
        @NamedQuery(name = "loadAllWorkDetails", query = "from WorkDetail"),
        @NamedQuery(name = "loadAllActiveWorkDetailsForWorkplace", query = "from WorkDetail where workplace = :workplace and is_active = true"),
        @NamedQuery(name = "loadWorkDetailByDescriptionAndWorkplace", query = "from WorkDetail where description = :description and workplace = :workplace"),
})

@Entity
@Table(name = "work_detail")
public class WorkDetail extends DBModel {

    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;

    @ManyToOne
    @JoinColumn(name = "workplace_id")
    private Workplace workplace;

    @Column(name = "description")
    private String description;

    @Column(name = "is_active")
    private boolean isActive;


    @Override
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setWorkplace(Workplace workplace) {
        this.workplace = workplace;
    }

    public Workplace getWorkplace() {
        return workplace;
    }

    public void setIsActive(boolean isActive) {
        this.isActive = isActive;
    }

    @Override
    public boolean getIsActive() {
        return true;
    }

    @Override
    public String getDisplayLabel() {
        return getDescription();
    }

    @Override
    public int compareTo(Object o) {
        if (!(o instanceof WorkDetail)) {
            return -1;
        } else {
            WorkDetail otherWorkDetail = (WorkDetail) o;
            return getDisplayLabel().compareTo(otherWorkDetail.getDisplayLabel());
        }
    }
}
